package com.ktjiaoyu.crm.web.controller;

import com.ktjiaoyu.crm.entity.CustLost;
import com.ktjiaoyu.crm.service.ILostService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.data.domain.Sort;
import org.springframework.ui.Model;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "/cust")
public class LostController {
    @Resource
    private ILostService lostService;//客户流失

    //客户流失列表
    @RequestMapping(value = "/lostList")
    public String lostList(Model model, String custName,
                           @RequestParam(required = false, defaultValue = "1") int pageIndex) {
        Pageable pageable = PageRequest.of(pageIndex - 1, 5, Sort.by(Sort.Direction.ASC, "lstId"));
        Page<CustLost> lostPage = lostService.findAllLost(custName, pageable);
        model.addAttribute("lostPage", lostPage);
        model.addAttribute("custName", custName);
        return "customer/lost/lost_list";
    }
}
